home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 September / Chip_2000-09_cd1.bin / sharewar / Slunec / app / 16 / ARCHIVES.SWG / 0013_TAR EXPLANATION.pas < prev    next >
Pascal/Delphi Source File  |  1996-09-03  |  12KB  |  270 lines

  1. --------A-TAR-G-----------------------------
  2.  
  3. The  Unix  Tape ARchives mostly have  the  extension TAR. The info about
  4. this comes from a magic file, thus useful only for identification.
  5.  
  6. --------A-TAR-------------------------------
  7.  
  8. The  Unix  TAR  program is an archiver  program  which stores files in a
  9. single archive without compression.
  10.  
  11. OFFSET Count TYPE Description
  12. @section The Standard Format
  13.  
  14. A  @dfn{tar  tape}  or file contains  a  series  of records. Each record
  15. contains @code{RECORDSIZE} bytes. Although this format may be thought of
  16. as being on magnetic tape, other media are often used.
  17.  
  18. Each file archived is represented by a header record which describes the
  19. file,  followed  by zero or more records  which give the contents of the
  20. file.  At the end of the archive file  there may be a record filled with
  21. binary  zeros as an end-of-file marker. A reasonable system should write
  22. a  record  of zeros at the end, but  must  not assume that such a record
  23. exists when reading an archive.
  24.  
  25. The records may be @dfn{blocked} for physical I/O operations. Each block
  26. of  @var{N}  records  (where @var{N} is  set  by the @samp{-b} option to
  27. @code{tar})  is  written  with  a  single  @code{write()}  operation. On
  28. magnetic tapes, the result of such a write is a single tape record. When
  29. writing  an archive, the last block of  records should be written at the
  30. full  size,  with records after the  zero  record containing all zeroes.
  31. When  reading an archive, a reasonable  system should properly handle an
  32. archive  whose  last block is shorter  than  the rest, or which contains
  33. garbage records after a zero record.
  34.  
  35. The header record is defined in C as follows:
  36.  
  37. @example
  38. /*
  39.  * Standard Archive Format - Standard TAR - USTAR
  40.  */
  41. #define  RECORDSIZE  512
  42. #define  NAMSIZ      100
  43. #define  TUNMLEN      32
  44. #define  TGNMLEN      32
  45.  
  46. union record @{
  47.     char        charptr[RECORDSIZE];
  48.     struct header @{
  49.         char    name[NAMSIZ];
  50.         char    mode[8];
  51.         char    uid[8];
  52.         char    gid[8];
  53.         char    size[12];
  54.         char    mtime[12];
  55.         char    chksum[8];
  56.         char    linkflag;
  57.         char    linkname[NAMSIZ];
  58.         char    magic[8];
  59.         char    uname[TUNMLEN];
  60.         char    gname[TGNMLEN];
  61.         char    devmajor[8];
  62.         char    devminor[8];
  63.     @} header;
  64. @};
  65.  
  66. /* The checksum field is filled with this while the checksum is computed. */
  67. #define    CHKBLANKS    "        "        /* 8 blanks, no null */
  68.  
  69. /* The magic field is filled with this if uname and gname are valid. */
  70. #define    TMAGIC    "ustar  "        /* 7 chars and a null */
  71.  
  72. /* The magic field is filled with this if this is a GNU format dump entry */
  73. #define    GNUMAGIC  "GNUtar "        /* 7 chars and a null */
  74.  
  75. /* The linkflag defines the type of file */
  76. #define  LF_OLDNORMAL '\0'       /* Normal disk file, Unix compatible */
  77. #define  LF_NORMAL    '0'        /* Normal disk file */
  78. #define  LF_LINK      '1'        /* Link to previously dumped file */
  79. #define  LF_SYMLINK   '2'        /* Symbolic link */
  80. #define  LF_CHR       '3'        /* Character special file */
  81. #define  LF_BLK       '4'        /* Block special file */
  82. #define  LF_DIR       '5'        /* Directory */
  83. #define  LF_FIFO      '6'        /* FIFO special file */
  84. #define  LF_CONTIG    '7'        /* Contiguous file */
  85.  
  86. /* Further link types may be defined later. */
  87.  
  88. /* Bits used in the mode field - values in octal */
  89. #define  TSUID    04000        /* Set UID on execution */
  90. #define  TSGID    02000        /* Set GID on execution */
  91. #define  TSVTX    01000        /* Save text (sticky bit) */
  92.  
  93. /* File permissions */
  94. #define  TUREAD   00400        /* read by owner */
  95. #define  TUWRITE  00200        /* write by owner */
  96. #define  TUEXEC   00100        /* execute/search by owner */
  97. #define  TGREAD   00040        /* read by group */
  98. #define  TGWRITE  00020        /* write by group */
  99. #define  TGEXEC   00010        /* execute/search by group */
  100. #define  TOREAD   00004        /* read by other */
  101. #define  TOWRITE  00002        /* write by other */
  102. #define  TOEXEC   00001        /* execute/search by other */
  103. @end example
  104.  
  105. All  characters  in  header  records  are  represented  by  using  8-bit
  106. characters  in  the  local  variant  of  ASCII.  Each  field  within the
  107. structure  is  contiguous; that is, there  is no padding used within the
  108. structure. Each character on the archive medium is stored contiguously.
  109.  
  110. Bytes  representing  the contents of files  (after  the header record of
  111. each  file)  are  not translated in any  way  and are not constrained to
  112. represent  characters  in any character  set. The @code{tar} format does
  113. not distinguish text files from binary files, and no translation of file
  114. contents is performed.
  115.  
  116. The   @code{name},  @code{linkname},   @code{magic},  @code{uname},  and
  117. @code{gname} are null-terminated character strings. All other fileds are
  118. zero-filled  octal numbers in ASCII. Each numeric field of width @var{w}
  119. contains   @var{w}@minus{}  2  digits,  a  space,  and  a  null,  except
  120. @code{size}, and @code{mtime}, which do not contain the trailing null.
  121.  
  122. The  @code{name} field is the pathname of the file, with directory names
  123. (if any) preceding the file name, separated by slashes.
  124.  
  125. The @code{mode} field provides nine bits specifying file permissions and
  126. three  bits  to specify the Set UID,  Set GID, and Save Text (``stick'')
  127. modes. Values for these bits are defined above. When special permissions
  128. are  required to create a file with a given mode, and the user restoring
  129. files  from the archive does not  hold such permissions, the mode bit(s)
  130. specifying  those  special permissions are  ignored. Modes which are not
  131. supported  by the operating system restoring files from the archive will
  132. be  ignored.  Unsupported  modes  should be  faked  up  when creating or
  133. updating  an archive; e.g. the group permission could be copied from the
  134. @code{other} permission.
  135.  
  136. The  @code{uid} and @code{gid} fields are  the numeric user and group ID
  137. of  the  file  owners, respectively. If  the  operating  system does not
  138. support numeric user or group IDs, these fields should be ignored.
  139.  
  140. The @code{size} field is the size of the file in bytes; linked files are
  141. archived  with this field specified  as zero. @xref{Extraction Options};
  142. in particular the @samp{-G} option.@refill
  143.  
  144. The  @code{mtime} field is the modification time of the file at the time
  145. it  was  archived. It is the ASCII  representation of the octal value of
  146. the last time the file was modified, represented as an integer number of
  147. seconds since January 1, 1970, 00:00 Coordinated Universal Time.
  148.  
  149. The  @code{chksum} field is the ASCII  representation of the octal value
  150. of  the simple sum of all bytes in the header record. Each 8-bit byte in
  151. the  header  is added to an  unsigned  integer, initialized to zero, the
  152. precision   of  which  shall  be  no  less  than  seventeen  bits.  When
  153. calculating  the  checksum, the @code{chksum} field  is treated as if it
  154. were all blanks.
  155.  
  156. The  @code{typeflag}  field  specifies the type  of  file archived. If a
  157. particular  implementation  does not recognize  or  permit the specified
  158. type,  the file will be extracted as if  it were a regular file. As this
  159. action occurs, @code{tar} issues a warning to the standard error.
  160.  
  161. @table @code
  162. @item LF_NORMAL
  163. @itemx LF_OLDNORMAL
  164. These  represent  a regular file. In  order  to be compatible with older
  165. versions  of @code{tar}, a  @code{typeflag} value of @code{LF_OLDNORMAL}
  166. should  be silently recognized as a regular file. New archives should be
  167. created   using  @code{LF_NORMAL}.  Also,  for  backward  compatibility,
  168. @code{tar}  treats  a  regular file whose name  ends  with  a slash as a
  169. directory.
  170.  
  171. @item LF_LINK
  172. This  represents a file linked to  another file, of any type, previously
  173. archived. Such files are identified in Unix by each file having the same
  174. device  and  inode  number.  The  linked-to  name  is  specified  in the
  175. @code{linkname} field with a trailing null.
  176.  
  177. @item LF_SYMLINK
  178. This  represents a symbolic link to  another file. The linked-to name is
  179. specified in the @code{linkname} field with a trailing null.
  180.  
  181. @item LF_CHR
  182. @itemx LF_BLK
  183. These   represent  character  special  files  and  block  special  files
  184. respectively.  In  this  case  the  @code{devmajor}  and @code{devminor}
  185. fields  will  contain the major  and  minor device numbers respectively.
  186. Operating  systems may map the device  specifications to their own local
  187. specification, or may ignore the entry.
  188.  
  189. @item LF_DIR
  190. This  specifies a directory or sub-directory.  The directory name in the
  191. @code{name}  field  should  end  with a  slash.  On  systems  where disk
  192. allocation  is performed on a directory basis the @code{size} field will
  193. contain the maximum number of bytes (which may be rounded to the nearest
  194. disk  block allocation unit) which the directory may hold. A @code{size}
  195. field  of zero indicates no such  limiting. Systems which do not support
  196. limiting in this manner should ignore the @code{size} field.
  197.  
  198. @item LF_FIFO
  199. This  specifies  a FIFO special file. Note  that the archiving of a FIFO
  200. file archives the existence of this file and not its contents.
  201.  
  202. @item LF_CONTIG
  203. This  specifies  a contiguous file, which is  the  same as a normal file
  204. except  that,  in operating systems which  support  it, all its space is
  205. allocated contiguously on the disk. Operating systems which do not allow
  206. contiguous allocation should silently treat this type as a normal file.
  207.  
  208. @item 'A' @dots{}
  209. @itemx 'Z'
  210. These are reserved for custom implementations. Some of these are used in
  211. the GNU modified format, as described below. @end table
  212.  
  213. Other  values are reserved for specification  in future revisions of the
  214. P1003 standard, and should not be used by any @code{tar} program.
  215.  
  216. The  @code{magic}  field indicates that this  archive  was output in the
  217. P1003   archive  format.  If  this  field  contains  @code{TMAGIC},  the
  218. @code{uname}   and   @code{gname}   fields   will   contain   the  ASCII
  219. representation  of  the  owner and group  of  the  file respectively. If
  220. found,  the  user and group ID represented  by  these names will be used
  221. rather than the values within the @code{uid} and @code{gid} fields.
  222.  
  223. @section  GNU  Extensions  to  the Archive  Format  The  GNU format uses
  224. additional  file  types  to describe new  types  of files in an archive.
  225. These are listed below.
  226.  
  227. @table @code
  228. @item LF_DUMPDIR
  229. @itemx 'D'
  230. This represents a directory and a list of files created by the @samp{-G}
  231. option.  The  @code{size} field gives the  total  size of the associated
  232. list  of  files. Each filename is  preceded  by either a @code{'Y'} (the
  233. file  should  be  in  this  archive) or  an  @code{'N'}  (The  file is a
  234. directory, or is not stored in the archive). Each filename is terminated
  235. by a null. There is an additional null after the last filename.
  236.  
  237. @item LF_MULTIVOL
  238. @itemx 'M'
  239. This  represents a file continued from  another volume of a multi-volume
  240. archive created with the @samp{-M} option. The original type of the file
  241. is  not given here. The @code{size} field gives the maximum size of this
  242. piece  of the file (assuming the volume  does not end before the file is
  243. written  out).  The  @code{offset}  field  gives  the  offset  from  the
  244. beginning  of  the  file  where  this  part  of  the  file  begins. Thus
  245. @code{size}  plus  @code{offset} should equal  the  original size of the
  246. file.
  247.  
  248. @item LF_VOLHDR
  249. @itemx 'V'
  250. This file type is used to mark the volume header that was given with the
  251. @samp{-V}  option  when the archive  was  created. The @code{name} field
  252. contains   the  @code{name}  given  after   the  @samp{-V}  option.  The
  253. @code{size}  field  is  zero. Only the first  file  in each volume of an
  254. archive should have this type.
  255.  
  256. @end table
  257. EXTENSION:
  258. OCCURENCES:
  259. PROGRAMS:
  260. REFERENCE:
  261. SEE ALSO:
  262. VALIDATION:
  263. OFFSET              Count TYPE   Description
  264. 0000h                 256 byte   Other header info ?
  265. 0100h                   6 char   ID='ustar',0
  266. EXTENSION:TAR
  267. OCCURENCES:PC, Unix
  268. PROGRAMS:TAR
  269.  
  270.